package com.xjh.him.utils;

import java.util.Date;

public class DateUtils {

    public static String getIntervalTime(Date date) {
        Date now = new Date();
        long intervalMillis = now.getTime() - date.getTime();
        long div = 1000L * 3600 * 24 * 365;
        long offYear = intervalMillis / div;
        if (offYear > 0) {
            return offYear + "年前";
        }

        div /= 12;
        long offMonth = intervalMillis / div;
        if (offMonth > 0) {
            return offMonth + "月前";
        }

        div /= 30;
        long offDay = intervalMillis / div;
        if (offDay == 1) {
            return "昨天";
        }else if (offDay > 1) {
            return offDay + "天前";
        }

        div /= 24;
        long offHour = intervalMillis / div;
        if (offHour > 0) {
            return offHour + "小时前";
        }

        div /= 60;
        long offMinute = intervalMillis / div;
        if (offMinute > 0) {
            return offMinute + "分钟前";
        }else {
            return "刚刚";
        }
    }
}
